const app = getApp();
const publicFun = require('/utils/public.js');
import { getCertificateDetail } from '/utils/request'
Page({
  data: {
    huodongid: 14, // 14气候行动 29自带杯 5减塑
  },
  onLoad(options) {
    this.setData({
      systemInfo: app.globalData.systemInfo,
      huodongid: options.id
    })
    my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff',
    });
    my.showLoading();
    this.getCertificateDetail();
  },
  applyClick() {
    let thisData = this.data;
    if(thisData.detailJson.cancanyu == 1){ // 可以申请
      my.navigateTo({
        url: '/pages/myCertificateApply/myCertificateApply?huodongid='+thisData.huodongid+'&name='+thisData.detailJson.name
      })
    }else{
      publicFun.showToast(thisData.detailJson.btnname);
    }
  },
  async getCertificateDetail() {
    try {
      let params = {
        huodongid: this.data.huodongid, // 14气候行动 28自带杯 5减塑
        userid: app.globalData.userid
      }
      const res = await getCertificateDetail(params);
      my.hideLoading();
      if(res.S == 1){
        res.des = publicFun.Base64.decode(res.des);
        res.quanyi = publicFun.Base64.decode(res.quanyi);
        this.setData({
          detailJson: res
        })
      }else{
        publicFun.showToast(res.M ? res.M : '加载失败');
      }
    } catch (e) {
      my.hideLoading();
      publicFun.showToast('失败，请稍后再试')
    }
  },
});
